package org.uoss.webapp.framework.json;

import java.util.Date;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

import org.uoss.core.util.DateTimeUtil;

public class JSONDateProcessor implements JsonValueProcessor{

	public Object processArrayValue(Object value, JsonConfig cfg) {
        String[] strDateArray = {};      
        if (value instanceof Date[]) {           
            Date[] dateArray = (Date[]) value;      
            strDateArray = new String[dateArray.length];      
            for (int i = 0; i < dateArray.length; i++) {      
            	strDateArray[i] = DateTimeUtil.format((Date)dateArray[i], DateTimeUtil.DATA_TIME_FORMAT_YYYY_MM_DD_HH_SS);     
            }      
        }      
        return strDateArray; 
	}

	public Object processObjectValue(String key, Object value, JsonConfig cfg) {
        if (value instanceof Date) {          
            return DateTimeUtil.format((Date)value, DateTimeUtil.DATA_TIME_FORMAT_YYYY_MM_DD_HH_SS);      
        }      
        return value == null ? null : value.toString();  
	}

}
